<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH 数据发布首页</title>
    <meta name="keywords" content="ZDH 数据发布首页">
    <meta name="description" content="ZDH 数据发布首页">

    <link rel="shortcut icon" href="img/favicon.ico">

    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <!--    <link rel="stylesheet" type="text/css" href="css/plugins/webuploader/webuploader.css">
        <link rel="stylesheet" type="text/css" href="css/demo/webuploader-demo.css">-->

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据发布</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                            <i class="fa fa-eye"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="javascript:void(0);" onclick="getResourceDesc()">功能说明</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="ibox-content">

                    <form id="issue_data_add_form" name="issue_data_add_form" method="post" class="form-horizontal"
                          action="">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">数据说明</label>
                            <div class="col-sm-10">
                                <input id="issue_context" name="issue_context" type="text"
                                       placeholder="数据说明" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">创建时间</label>
                            <div class="col-sm-10">
                                <input id="create_time" name="create_time" type="text" readonly
                                       placeholder="创建时间" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <!-- 输入数据源开始-->
                        <div class="form-group">
                            <label class="col-sm-2 control-label">选择数据源</label>
                            <div class="col-sm-10">
                                <select id="data_sources_choose_input" name="data_sources_choose_input"
                                        data-placeholder="选择数据源..."
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="" mytype="">选择数据源...</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">数据源类型</label>
                            <div class="col-sm-10">
                                <input id="data_source_type_input" name="data_source_type_input" type="text" readonly
                                       placeholder="数据源类型" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">输入表名/文件名</label>
                            <div class="col-sm-10" id="div_data_sources_table_name_input">
                                <select id="data_sources_table_name_input" name="data_sources_table_name_input"
                                        data-placeholder="选择数据表..."
                                        class="chosen-select form-control m-b" tabindex="2">
                                    <option value="">选择数据表...</option>
                                </select>
                            </div>

                            <div class="col-sm-10" id="div_data_sources_file_name_input">
                                <input id="data_sources_file_name_input" name="data_sources_file_name_input" type="text"
                                       placeholder="文件全路径" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>



                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">配置选择的列</label>
                            <div class="col-sm-10" id="div_data_sources_file_columns">
                                <div class="input-group">
                                    <input id="data_sources_file_columns" name="data_sources_file_columns" type="text"
                                           placeholder="配置选择的列逗号分割"
                                           aria-required="true" class="form-control"> <span class="input-group-btn"> <button
                                        id="btn_columns_file" type="button" class="btn btn-primary"
                                        οnsubmit='return false'>获取
                                   </button></span>
                                </div>
                                <span class="help-block m-b-none">配置JDBC数据源,选择表,之后点击[获取按钮]自动生成字段映射</span>
                                <span class="help-block m-b-none">配置HDFS数据源,手动输入列字段,逗号分割,之后点击[获取按钮]自动生成字段映射</span>
                                <span class="help-block m-b-none">配置HBASE数据源,手动输入列字段格式 列族:列名,逗号分割,之后点击[获取按钮]自动生成字段映射</span>
                            </div>
                            <div class="col-sm-10" id="div_data_sources_table_columns">
                                <div class="input-group">
                                    <input id="data_sources_table_columns" name="data_sources_table_columns" type="text"
                                           placeholder="配置选择的列逗号分割"
                                           aria-required="true" class="form-control"> <span class="input-group-btn"> <button
                                        id="btn_columns" type="button" class="btn btn-primary" οnsubmit='return false'>获取
                                        </button></span>
                                </div>
                                <span class="help-block m-b-none">配置JDBC数据源,选择表,之后点击[获取按钮]自动生成字段映射</span>
                                <span class="help-block m-b-none">配置HDFS数据源,手动输入列字段,逗号分割,之后点击[获取按钮]自动生成字段映射</span>
                                <span class="help-block m-b-none">配置HBASE数据源,手动输入列字段格式 列族:列名,逗号分割,之后点击[获取按钮]自动生成字段映射</span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group">

                            <label class="col-sm-2 control-label">配置字段映射</label>
                            <div class="col-sm-10">

                                <!-- Example Events -->
                                <div class="btn-group">
                                    <button id="add_row" class="btn btn-primary btn-xs" type="button"
                                            style="height: 20px" onclick='addRow("zdh_add_expr")'
                                            οnsubmit='return false'><i class="glyphicon glyphicon-plus"
                                                                       aria-hidden="true"></i></button>
                                    <!--<button class="btn btn-primary" type="button">中</button>-->
                                    <!--<button class="btn btn-white" type="button">右</button>-->
                                    <input id="row_num" type="text"
                                           placeholder="行号" style="width: 30px;height: 20px">
                                </div>

                                <table id="exampleTableEvents" name="exampleTableEvents" data-height="250"
                                       data-mobile-responsive="false">

                                </table>
                                <!-- End Example Events -->

                            </div>


                        </div>


                        <div class="hr-line-dashed"></div>
                        <!-- 输入数据源结束-->

                        <!-- 元信息 业务相关-->

                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属公司</label>
                            <div class="col-sm-10">
                                <input id="company" name="company"
                                       type="text"
                                       placeholder="填写公司" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属部门</label>
                            <div class="col-sm-10">
                                <input id="section" name="section"
                                       type="text"
                                       placeholder="填写部门" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">所属业务</label>
                            <div class="col-sm-10">
                                <input id="service" name="service"
                                       type="text"
                                       placeholder="填写业务" class="form-control" aria-required="true"> </span>
                            </div>
                        </div>

                        <div class="form-group col-sm-12" id="label_div">

                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">更新说明</label>
                            <div class="col-sm-10">
                                <textarea id="update_context" name="update_context" class="form-control" rows="2"
                                          placeholder="更新说明"></textarea>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <!-- 输出数据源结束-->

                        <div class="form-group">
                            <div class="text-center">
                                <button id="save_issue_data" name="save_zdh" class="btn btn-primary"
                                        οnsubmit='return false'
                                        type="button">保存
                                </button>
                                <button id="update_issue_data" name="update_zdh" class="btn btn-primary"
                                        οnsubmit='return false'
                                        type="button">更新
                                </button>
                                <button id="reset" class="btn btn-white" type=reset>清空</button>
                            </div>
                        </div>


                    </form>


                </div>
            </div>


        </div>
    </div>
</div>

<script src="js/zdh_common.js"></script>
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- Bootstrap table -->
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- 自定义js -->
<script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="js/hplus.js?v=4.1.0"></script>
<script src="js/content.js?v=1.0.0"></script>

<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<!-- layer javascript -->
<script src="js/plugins/layer/layer.min.js"></script>

<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });

    function load_label() {
        var label_template = " <label class='col-sm-2'>label_name</label>\n";
        var a_template = "<button type=\"button\" class=\"btn btn-outline btn-default\" enum_value=\"enum_value_replace\">enum_context</button>\n";
        var line_template = "                                <br/>\n";
        $.ajax({
            type: 'POST',
            async: false,
            url: server_context+"/data_ware_house_label",
            dataType: 'json',
            data: '',
            //成功返回
            success: function (data) {
                $('#label_div').html("");
                if(data.result.length>0){
                    for(var i=0;i<data.result.length;i++){
                        var dt = data.result[i];
                        var label_html = label_template.replace("label_name", dt.enum_context);

                        if(dt.enum_json_object.length>0){
                            for (var j=0;j<dt.enum_json_object.length;j++){
                                label_html=label_html+a_template.replace("enum_value_replace",dt.enum_json_object[j].enum_value).replace("enum_context", dt.enum_json_object[j].enum_value_context);
                            }
                        }
                        label_html = label_html+line_template;
                        $('#label_div').append(label_html);
                    }
                }

                $('#label_div button').click(function () {
                    if($(this).hasClass("btn-default")){
                        $(this).removeClass("btn-default");
                        $(this).addClass("btn-info")
                    }else{
                        $(this).removeClass("btn-info");
                        $(this).addClass("btn-default");
                    }
                });
            },
            //处理完成
            complete: function () {
                console.info("etl_task_complete")
            },
            //报错
            error: function (data) {
                console.info("etl_task_error: " + data.responseText);
            }
        });
    }

    (function (document, window, $) {


        (function () {

            var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
            var params = url.substr(1);//去掉问号
            var pa = params.split("&");
            var s = new Object();//定义一个全局变量-存储任务ID
            for (var i = 0; i < pa.length; i++) {
                s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
            }
            load_label();
            //定义特定数据源展示的div
            function fileShow() {
                console.info("fileShow");
                $('#div_data_sources_table_name_input')[0].style.display = 'none';
                $('#div_data_sources_file_name_input')[0].style.display = 'block';
                //表字段
                $('#div_data_sources_table_columns')[0].style.display = 'none';
                $('#div_data_sources_file_columns')[0].style.display = 'block';

            }

            function tableShow() {
                console.info("tableShow");
                $('#div_data_sources_table_name_input')[0].style.display = 'block';
                $('#div_data_sources_file_name_input')[0].style.display = 'none';
                //表字段
                $('#div_data_sources_table_columns')[0].style.display = 'block';
                $('#div_data_sources_file_columns')[0].style.display = 'none';

            }

            //初始化数据源--把所有数据源都加载到下拉框
            function init_data_sources() {
                $.ajax({
                    type: 'POST',
                    url: server_context+"/data_sources_list",
                    dataType: 'json',
                    async: false,
                    data: '',
                    //成功返回
                    success: function (data) {
                        if(data.code != "200"){
                            layer.msg(data.msg);
                            return ;
                        }
                        var str = '<option value=\"\" mytype=\"\" hassubinfo=\"true\"></option>';
                        for (var i = 0; i < data.result.length; i++) {
                            str += '<option value=\"' + data.result[i].id + "\" mytype=\"" + data.result[i].data_source_type + "\" hassubinfo=\"true\">" + data.result[i].data_source_context + "</option>"
                        }
                        //输入数据源类型下拉框
                        $('#data_sources_choose_input').html(str);
                        $('#data_sources_choose_input').chosen().on("change", function (evt, params) {
                            // alert($('#data_sources_choose_input').val())
                            $('#data_source_type_input').val($('#data_sources_choose_input').find("option:selected").attr("mytype"));
                            $("#data_sources_choose_input").trigger("chosen:updated");

                            if ($('#data_sources_choose_input').find("option:selected").attr("mytype") == 'JDBC') {
                                //alert("==========="+$('#data_sources_choose_input').val())

                                init_table_name($('#data_sources_choose_input').val());
                            } else {
                                //fileShow()
                                //表名
                                $('#div_data_sources_table_name_input')[0].style.display = 'none';
                                //表字段
                                $('#div_data_sources_table_columns')[0].style.display = 'none';
                                $('#div_data_sources_file_name_input')[0].style.display = 'block';
                                $('#div_data_sources_file_columns')[0].style.display = 'block';
                            }
                        });

                    },
                    //处理完成
                    complete: function () {
                        console.info("complete")
                    },
                    //报错
                    error: function (data) {
                        console.info("error: " + data.responseText);
                    }
                });
            }

            //获取table 中包含的字段函数
            $("#btn_columns").click(function () {

                if ($("#data_sources_table_name_input").val() == '') {
                    layer.msg("表名/文件名不能为空!");
                }

                var postData = {
                    id: $("#data_sources_choose_input").val(),
                    table_name: $("#data_sources_table_name_input").val(),
                };

                $.ajax({
                    type: 'POST',
                    url: server_context+"/etl_task_schema",
                    dataType: 'json',
                    async: false,
                    data: postData,
                    //成功返回
                    success: function (data) {
                        if(data.code == "200"){
                            $('#row_num').val('');
                            var str = '';
                            for (var i = 0; i < data.result.length; i++) {
                                if (str == '')
                                    str = data.result[i];
                                else
                                    str += "," + data.result[i];
                                addRow(data.result[i])
                            }
                            $("#data_sources_table_columns").val(str)
                        }else{
                            layer.msg(data.msg);
                            var columns = $("#data_sources_table_columns").val().split(",");
                            for (var i = 0; i < columns.length; i++) {
                                if(!is_empty(columns[i])){
                                    addRow(columns[i])
                                }
                            }
                        }

                    },
                    //处理完成
                    complete: function () {
                        console.info("complete")
                    },
                    //报错
                    error: function (data) {
                        layer.msg(data.responseText);
                        console.info("error: " + data.responseText);
                    }
                });

            })

            $("#btn_columns_file").click(function () {
                var cols = $('#data_sources_file_columns').val();
                if (cols == '') {
                    layer.msg("配置选择的列不能为空!");
                }
                var cols_ary = cols.split(',');
                for (var i = 0; i < cols_ary.length; i++) {
                    addRow(cols_ary[i])
                }

            });

            //根据数据源id 获取对应的tables
            function init_table_name(id) {

                //alert("datasourceid:"+id)
                var postData = {
                    id: id,
                };
                $.ajax({
                    type: 'POST',
                    url: server_context+"/etl_task_tables",
                    dataType: 'json',
                    async:false,
                    data: postData,
                    //成功返回
                    success: function (data) {
                        if(data.code != "200"){
                            layer.msg(data.msg);
                            return ;
                        }
                        var str = '<option value=\"\" hassubinfo=\"true\"></option>';
                        for (var i = 0; i < data.result.length; i++) {
                            str += '<option value=\"' + data.result[i] + '\" hassubinfo=\"true\">' + data.result[i] + '</option>';
                        }

                        $('#div_data_sources_file_name_input')[0].style.display = 'none';

                        $('#div_data_sources_file_columns')[0].style.display = 'none';

                        $('#div_data_sources_table_name_input')[0].style.display = 'block';
                        //表字段
                        $('#div_data_sources_table_columns')[0].style.display = 'block';

                        $('#data_sources_table_name_input').html(str);

                        $('#data_sources_table_name_input').trigger("chosen:updated");

                        $('#data_sources_table_name_input').chosen();


                    },
                    //处理完成
                    complete: function () {
                        console.info("init_table_name ajax complete")
                    },
                    //报错
                    error: function (data) {
                        console.info("error: " + data.responseText);
                    }
                });


            }

            window.operateEvents = {
                'click #del': function (e, value, row, index) {
                    $('#exampleTableEvents').bootstrapTable('remove', {field: 'column_md5', values: [row.column_md5]});
                }
            };

            function operateFormatter(value, row, index) {
                return [
                    ' <button id="del" name="del" type="button" class="btn btn-outline btn-sm">\n' +
                    '                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>\n' +
                    '                                    </button>'
                ].join('');
            }

            //初始化 bootstrap table
            $('#exampleTableEvents').bootstrapTable({
                url: "",
                search: false,
                clickEdit: true,
                pagination: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                useRowAttrFunc: true,
                iconSize: 'outline',
                //toolbar: '#exampleTableEventsToolbar',
                icons: {
                    refresh: 'glyphicon-repeat',
                    toggle: 'glyphicon-list-alt',
                    columns: 'glyphicon-list'
                },
                columns: [
                    {
                        field: 'nu',
                        title: '序号',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    }, {
                        field: 'column_md5',
                        title: '字段序列码'
                    }, {
                        field: 'column_name',
                        title: '原始字段',
                        sortable: false
                    },{
                        field: 'column_type',
                        title: '数据类型',
                        sortable: false
                    }, {
                        field: 'column_desc',
                        title: '数据说明',
                        sortable: false
                    }, {
                        field: 'operate',
                        title: '操作',
                        events: operateEvents,//给按钮注册事件
                        width: 45,
                        formatter: operateFormatter //表格中增加按钮
                    }],
                onDblClickCell: function (field, value, row, $element) {
                    $element.attr('contenteditable', true);
                    $element.blur(function () {
                        var index = $element.parent().data('index');
                        var tdValue = $element.html().replace("<br>", "");
                        saveData(index, field, tdValue);
                    })
                }
            });

            function saveData(index, field, value) {
                $('#exampleTableEvents').bootstrapTable('updateCell', {
                    index: index,       //行索引
                    field: field,       //列名
                    value: value        //cell值
                })
            }

            fileShow();
            //启动数据源select 初始化函数
            init_data_sources();
            //s.id=-1 表示新增,否则表示更新
            if (s.id == -1) {
                console.info("新增按钮触发");
                //$('#data_sources_table_name_input').chosen();
                //$('#data_sources_table_name_output').chosen();
                $('#save_issue_data').show();
                $('#update_issue_data').hide()

            } else {
                $('#save_issue_data').hide();
                $('#update_issue_data').show();

                buildParam()
            }

            function getMyDate(str) {
                var oDate = new Date(str),
                    oYear = oDate.getFullYear(),
                    oMonth = oDate.getMonth() + 1,
                    oDay = oDate.getDate(),
                    oHour = oDate.getHours(),
                    oMin = oDate.getMinutes(),
                    oSen = oDate.getSeconds(),
                    oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + " " + getzf(oHour) + ":" + getzf(oMin) + ":" + getzf(oSen);//最后拼接时间
                return oTime;
            };

            //补0操作
            function getzf(num) {
                if (parseInt(num) < 10) {
                    num = '0' + num;
                }
                return num;
            }


            function buildParam() {
                $('#enable_quality').prop("checked", false);
                if (s.id != '-1') {
                    console.info("更新按钮触发--开始赋值对应参数");
                    //开始赋值

                    $.ajax({
                        url: server_context+"/data_ware_house_list",
                        data: "id=" + s.id,
                        type: "post",
                        async: false,
                        dataType: "json",
                        success: function (data) {
                            if(data.code != "200"){
                                layer.msg(data.msg);
                                return ;
                            }
                            console.info("success");
                            // layer.alert(JSON.stringify(data[0]))

                            // 基础信息加载
                            $('#issue_context').val(data.result.issue_context);
                            $('#create_time').val(getMyDate(data.result.create_time));
                            $('#data_source_type_input').val(data.result.data_source_type_input);

                            $("#data_sources_choose_input").val(data.result.data_sources_choose_input);
                            $("#data_sources_choose_input").trigger("chosen:updated");

                            $('#data_sources_file_name_input').val(data.result.data_sources_table_name_input);
                            $('#user_name').val(data.result.user_name);
                            $('#company').val(data.result.company);
                            $('#section').val(data.result.section);
                            $('#service').val(data.result.service);

                            //字段列表
                            if(data.result.data_source_type_input=="JDBC"){
                                init_table_name(data.result.data_sources_choose_input);
                                $('#data_sources_table_columns').val(data.result.data_sources_table_columns);
                                $('#data_sources_table_name_input').val(data.result.data_sources_table_name_input);
                                $("#data_sources_table_name_input").trigger("chosen:updated");

                            }else{
                                fileShow();
                                $('#data_sources_file_columns').val(data.result.data_sources_file_columns)
                            }



                            // 字段信息加载
                            var column_datas = data.result.column_datas;
                            var cd = JSON.parse(column_datas);
                            for (var i = 0; i < cd.length; i++) {
                                var index = $('#exampleTableEvents').bootstrapTable('getData').length;
                                $('#exampleTableEvents').bootstrapTable('insertRow', {
                                    index: index,
                                    row: {
                                         column_md5: cd[i].column_md5,
                                        column_name: cd[i].column_name,
                                        //column_expr: cd[i].column_expr,
                                        column_type: cd[i].column_type,
                                        //column_length: cd[i].column_length,
                                        column_is_null: cd[i].column_is_null,
                                        //column_regex: cd[i].column_regex,
                                        column_desc: cd[i].column_desc,
                                        //column_alias: cd[i].column_alias
                                    }
                                });
                            }

                            //加载标签信息
                            if(data.result.label_params!=""){

                                for(label_name of data.result.label_params.split(','))
                                $('#label_div button').each(function ( index,element){
                                    console.info(label_name);
                                    if($(this).attr('enum_value') == label_name){
                                        $(this).removeClass("btn-default");
                                        if($(this).hasClass("btn-info") != "true") {
                                            $(this).addClass("btn-info");
                                        }
                                    }
                                });
                            }


                        },
                        error: function (data) {
                            console.info("error: " + data.responseText);
                        }

                    });


                }
            }


            function openTabPage(url, title) {
                var wpd = $(window.parent.document);
                var mainContent = wpd.find('.J_mainContent');
                var thisIframe = mainContent.find("iframe[data-id='" + url + "']");
                var pageTabs = wpd.find('.J_menuTabs .page-tabs-content ');
                pageTabs.find(".J_menuTab.active").removeClass("active");
                mainContent.find("iframe").css("display", "none");
                if (thisIframe.length > 0) {	// 选项卡已打开
                    thisIframe.css("display", "inline");
                    pageTabs.find(".J_menuTab[data-id='" + url + "']").addClass("active");
                } else {
                    var menuItem = wpd.find("a.J_menuItem[href='" + url + "']");
                    var dataIndex = title == undefined ? menuItem.attr("data-index") : '9999';
                    var _title = title == undefined ? menuItem.find('.nav-label').text() : title;
                    var iframe = '<iframe class="J_iframe" name="iframe' + dataIndex + '" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url
                        + '" seamless="" style="display: inline;"></iframe>';
                    pageTabs.append(
                        ' <a href="javascript:;" class="J_menuTab active" data-id="' + url + '">' + _title + ' <i class="fa fa-times-circle"></i></a>');
                    mainContent.append(iframe);
                    //显示loading提示
                    var loading = top.layer.load();
                    mainContent.find('iframe:visible').load(function () {
                        //iframe加载完成后隐藏loading提示
                        top.layer.close(loading);
                    });
                }

            }

            function closeTab() {
               // var currentWidth = $(this).parents('.J_menuTab').width();
                var wpd = $(window.parent.document);
                var mainContent = wpd.find('.J_mainContent');
                var pageTabs = wpd.find('.J_menuTabs .page-tabs-content ');
                var currentTab=pageTabs.find(".J_menuTab.active");
                var closeTabId = currentTab.data('id');
                mainContent.find('.J_iframe');

                // 当前元素处于活动状态
                if (currentTab.hasClass('active')) {

                    // 当前元素后面有同辈元素，使后面的一个元素处于活动状态
                    if (pageTabs.next('.J_menuTab').size()) {

                        var activeId = currentTab.next('.J_menuTab:eq(0)').data('id');
                        currentTab.next('.J_menuTab:eq(0)').addClass('active');

                        mainContent.find('.J_iframe').each(function (index,e) {
                            if ($(e).data('id') == activeId) {
                                $(e).show().siblings('.J_iframe').hide();
                                return false;
                            }
                        });

                        var marginLeftVal = parseInt($('.page-tabs-content').css('margin-left'));
                        if (marginLeftVal < 0) {
                            pageTabs.animate({
                                marginLeft: (marginLeftVal + currentTab.width()) + 'px'
                            }, "fast");
                        }

                        //  移除当前选项卡
                        currentTab.remove();

                        // 移除tab对应的内容区
                        mainContent.find('.J_iframe').each(function (index,e) {
                            alert($(e).data('id'))
                            if ($(e).data('id') == closeTabId) {
                                $(e).remove();
                                return false;
                            }
                        });
                    }

                    // 当前元素后面没有同辈元素，使当前元素的上一个元素处于活动状态
                    if (currentTab.prev('.J_menuTab').size()) {
                        var activeId = currentTab.prev('.J_menuTab:last').data('id');
                        currentTab.prev('.J_menuTab:last').addClass('active');
                        mainContent.find('.J_iframe').each(function (index,e) {
                            if ($(e).data('id') == activeId) {
                                $(e).show().siblings('.J_iframe').hide();
                                return false;
                            }
                        });

                        //  移除当前选项卡
                        currentTab.remove();

                        // 移除tab对应的内容区
                        mainContent.find('.J_iframe').each(function (index,e) {
                            if ($(e).data('id') == closeTabId) {
                                $(e).remove();
                                return false;
                            }
                        });

                    }
                }
                // 当前元素不处于活动状态
                else {

                    //  移除当前选项卡
                    currentTab.remove();

                    // 移除相应tab对应的内容区
                    mainContent.find('.J_iframe').each(function (index,e) {
                        if ($(e).data('id') == closeTabId) {
                            $(e).remove();
                            return false;
                        }
                    });
                   // scrollToTab($('.J_menuTab.active'));
                }
                return false;
            }

            function save() {

                if ($('#issue_context').val() == '') {
                    layer.msg("发布任务说明不能为空！");
                    return;
                }

                var tableData = $("#exampleTableEvents").bootstrapTable('getData');

                var column_datas = new Array();// 声明一个数组
                for (var i = 0; i < tableData.length; i++) {
                    var column_data = {
                        column_md5: tableData[i].column_md5,
                        column_name: tableData[i].column_name,
                        column_type: tableData[i].column_type,
                        column_is_null: tableData[i].column_is_null,
                        column_desc: tableData[i].column_desc
                    };
                    column_datas.push(column_data)
                }
                var label_params = new Array();
                $('#label_div .btn-info').each(function ( index,element){
                    label_params.push($(this).attr('enum_value'));
                });
                $.ajax({
                    type: 'POST',
                    url: server_context+"/issue_data_add",
                    async: false,
                    dataType: 'json',
                    data: $("#issue_data_add_form").serialize() + "&" + "column_datas=" + encodeURIComponent(JSON.stringify(column_datas))+"&label_params="+label_params,
                    //发送数据前
                    beforeSend: function () {
                        // 禁用按钮防止重复提交
                        $("#save_issue_data").attr({disabled: "disabled"});
                    },
                    //成功返回
                    success: function (data) {
                        if(data.code != "200"){
                            parent.layer.msg(data.msg);
                            return
                        }
                        parent.layer.msg(data.msg);
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    },
                    //处理完成
                    complete: function () {
                        $("#save_issue_data").removeAttr('disabled');
                        console.info("complete")
                    },
                    //报错
                    error: function (data) {
                        $("#save_issue_data").removeAttr('disabled');
                        layer.error(data.responseText);
                        console.info("error: " + data.responseText);
                    }
                });

            }

            function update() {

                if ($('#issue_context').val() == '') {
                    layer.msg("ETL任务说明不能为空！");
                    return;
                }

                var tableData = $("#exampleTableEvents").bootstrapTable('getData');

                var column_datas = new Array();// 声明一个数组
                for (var i = 0; i < tableData.length; i++) {
                    var column_data = {
                        column_md5: tableData[i].column_md5,
                        column_name: tableData[i].column_name,
                        column_type: tableData[i].column_type,
                        column_is_null: tableData[i].column_is_null,
                        column_desc: tableData[i].column_desc
                    };
                    column_datas.push(column_data)
                }
                var label_params = new Array();
                $('#label_div .btn-info').each(function ( index,element){
                    label_params.push($(this).attr('enum_value'));
                });
                $.ajax({
                    type: 'POST',
                    url: server_context+"/issue_data_update",
                    async: false,
                    dataType: 'json',
                    data: $('#issue_data_add_form').serialize() + "&" + "column_datas=" + encodeURIComponent(JSON.stringify(column_datas))+ "&id=" +s.id+"&label_params="+label_params,
                    //发送数据前
                    beforeSend: function () {
                        // 禁用按钮防止重复提交
                        $("#update_issue_data").attr({disabled: "disabled"});
                    },
                    //成功返回
                    success: function (data) {
                        if(data.code != "200"){
                            parent.layer.msg(data.msg);
                            return
                        }
                        parent.layer.msg(data.msg);
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    },
                    //处理完成
                    complete: function () {
                        $("#update_issue_data").removeAttr('disabled');
                        console.info("complete")
                    },
                    //报错
                    error: function (data) {
                        $("#update_issue_data").removeAttr('disabled');
                        layer.error(data.responseText);
                        console.info("error: " + data.responseText);
                    }
                });

            }

            $('#save_issue_data').click(function (){
                save()
            });
            $('#update_issue_data').click(function (){
                update()
            })
        })();

    })(document, window, jQuery);

    //初始化a 标签 弹出具体参数解析功能
    function resovle_params() {

        layer.open({
            type: 1,
            shade: false,
            title: false, //不显示标题
            area: ["30%", "40%"],
            content: $('#data_sources_params'), //捕获的元素
            cancel: function (index) {
                layer.close(index);
                //this.content.show();
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构',{time: 5000});
            }
        });
    }

    //bootstrap table 增加一行
    function addRow(column) {
        var index = $('#row_num').val();
        if (index == '')
            index = $('#exampleTableEvents').bootstrapTable('getData').length;

        function guid() {
            return 'xxx-4xxx-yxxx-xx'.replace(/[xy]/g, function (c) {
                var r = Math.random() * 16 | 0,
                    v = c == 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        }

        if (column == "zdh_add_expr") {

            //column=guid()
            column = new Date().getTime()
        }
        var guid_str = guid()
        // newFlag == 1的数据为新规的数据
        $('#exampleTableEvents').bootstrapTable('insertRow', {
            index: index,
            row: {
                column_md5: guid_str,
                column_name: column,
                column_expr: column,
                column_type: "string",
                column_alias: column
            }
        });
    }

    function check_tb_name() {
        if ($('#data_source_type_output').val() == "JDBC") {

            if ($("#data_sources_table_name_output").html().search('<option value=\"' + $('#data_sources_file_name_output').val() + '\" hassubinfo="true">') == -1) {
                var op = '<option value=\"' + $('#data_sources_file_name_output').val() + '\" hassubinfo="true">' + $('#data_sources_file_name_output').val() + '</option>'

                $("#data_sources_table_name_output").html($("#data_sources_table_name_output").html() + op)
                $("#data_sources_table_name_output").trigger("chosen:updated");
                $("#data_sources_table_name_output").chosen();
                $("#data_sources_table_name_output").val($('#data_sources_file_name_output').val())
                $("#data_sources_table_name_output").trigger("chosen:updated");
            }
        }
    }

    function getFileName(o) {
        var pos = o.lastIndexOf("\\");
        return o.substring(pos + 1);
    }


</script>

</body>

</html>
